import {Component, OnInit, ViewContainerRef} from '@angular/core';
import {BakeTestRecord} from '../../../../model/BakeTestRecord';

import * as uuid from 'uuid';
import {NzModalService} from 'ng-zorro-antd/modal';
import {BaketestrecordeditComponent} from '../baketestrecordedit/baketestrecordedit.component';
import {AdminService} from "../../../../services/admin.service";
import {AlertService} from "../../../../services/alert.service";
@Component({
  selector: 'app-baketestrecordlist',
  templateUrl: './baketestrecordlist.component.html',
  styleUrls: ['./baketestrecordlist.component.css']
})
export class BaketestrecordlistComponent implements OnInit {
  tl:Array<BakeTestRecord>;
  constructor(private modal: NzModalService, private viewContainerRef: ViewContainerRef,
              private adminService:AdminService,private alertService:AlertService) {
    this.tl=new Array<BakeTestRecord>();
    this.initData();
  }

  ngOnInit(): void {
    this.initData();
  }

  initData(){
    this.adminService.getBakeTestRecords().then((data:any)=>{
      if(data.msg == "ok"){
        this.tl = data.list
      }else{
        this.alertService.showError("获取烘焙生产记录失败")

      }
    })

  }

  record(id:string){
    const modalwindow= this.modal.create({
      nzTitle: '烘焙豆检测信息编辑',
      nzContent: BaketestrecordeditComponent,
      nzViewContainerRef: this.viewContainerRef,
      nzComponentParams: {
      id:id
      },

      nzOnOk:()=>new Promise(resolve => {
        let temp=modalwindow.getContentComponent().b;
        if(!temp.qysj){
          this.alertService.showWarning('取样时间必填');
          resolve(false)
        }else if(!temp.sz){
          this.alertService.showWarning('色值必填')
        }else if(!temp.sf){
          this.alertService.showWarning('水分必填')
        }
        else {
          modalwindow.getContentComponent().save();
          setTimeout(()=>{

            resolve(true);
            //this.getEmpDetailByEmpid(this.empid);
            //this.loadEmpImg();
            this.initData();
          }, 2000)
        }

      })
    })


  }

  getBaketestsByClqk(c:string){
    this.adminService.getBaketestsByClqk(c).then((data:any)=>{
      if(data.msg == "ok"){
        this.tl = data.list
      }else{
        this.alertService.showError("根据处理情况查询检验失败")
      }
    })
  }

}
